using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Com.ArHat.Model.Models.Mapping
{
    public class MenuMap : EntityTypeConfiguration<Menu>
    {
        public MenuMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ImageUrl)
                .HasMaxLength(200);

            this.Property(t => t.NavigateUrl)
                .HasMaxLength(200);

            this.Property(t => t.Remark)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("Menus");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.ImageUrl).HasColumnName("ImageUrl");
            this.Property(t => t.NavigateUrl).HasColumnName("NavigateUrl");
            this.Property(t => t.Remark).HasColumnName("Remark");
            this.Property(t => t.SortIndex).HasColumnName("SortIndex");
            this.Property(t => t.ParentID).HasColumnName("ParentID");
            this.Property(t => t.ViewPowerID).HasColumnName("ViewPowerID");

            // Relationships
            this.HasOptional(t => t.Menu1)
                .WithMany(t => t.Menus1)
                .HasForeignKey(d => d.ParentID);

        }
    }
}
